#--Create timeseries data by categoryct_crime <- crime_bnt |>st_drop_geometry() |>group_by(category, date) |>tally() |>arrange(desc(n))#--Create shared_datashared_data_ct <- SharedData$new(ct_crime)#--Create filtermonth_slider_ct <- crosstalk::filter_slider("date", "Date", shared_data_ct, ~date, step =1, width ="100%")#--Trend plotpl_trend <- plotly::plot_ly(shared_data_ct, x =~date, y =~n, color =~category, colors =viridis_pal(option ="H")(14)) |> plotly::add_lines() |> plotly::layout(xaxis =list(title =""),yaxis =list(title ="Number of Crimes\n"))#--Pull everything togetherp1 <- crosstalk::bscols(widths =c(12, 12), month_slider_ct, pl_trend)p1
Code
#saveRDS(p1, here("1_data", "pl_trend.RDS"))
Overall Frequency
In the last three years
Code
#--Create count data by categoryct_crime2 <- crime_bnt |>st_drop_geometry() |>group_by(category) |>tally() |>arrange(desc(n)) #--Frequency plotpl_freq <-plot_ly(ct_crime2, x =~stats::reorder(category, n, decreasing =TRUE), y =~n, color =~category, colors =viridis_pal(option ="H")(14)) |> plotly::add_bars()|> plotly::layout(xaxis =list(title =""),yaxis =list(title ="Number of Crimes\n"))pl_freq
Code
#saveRDS(pl_freq, here("1_data", "pl_freq.RDS"))
In the last 12 months
Code
#--Create count data by category in the last 12 monthsct_crime3 <- crime_bnt |>st_drop_geometry() |>filter(date >=ymd("2023-04-01")) |>group_by(category) |>tally() |>arrange(desc(n)) #--Frequency plotpl_freq2 <-plot_ly(ct_crime3, x =~stats::reorder(category, n, decreasing =TRUE), y =~n, color =~category, colors =viridis_pal(option ="H")(14)) |> plotly::add_bars()|> plotly::layout(xaxis =list(title =""),yaxis =list(title ="Number of Crimes\n"))pl_freq2